package com.example.demo.Controller;

import com.example.demo.Entity.Person;
import com.example.demo.Service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/redisHash")
public class RedisHashRController {
    @Autowired
    private RedisService redisService;

    private String tableName="hashtable";

    @PutMapping("/person")
    public String putPerson(Person person){
        System.out.println("Person:"+person);
        redisService.hashPut(tableName,person);
        return "success put!!!";
    }

    @GetMapping("/person/{name}")
    public Object getPerson(@PathVariable("name") String name){
        return redisService.hashGet(tableName,name);
    }

    @GetMapping("/personName/{name}")
    public String getPersonName(@PathVariable("name") String name){
        return redisService.hashTestGet(tableName,name);
    }

    @DeleteMapping("/person/{name}")
    public String deletePerson(@PathVariable("name") String name){
        redisService.hashDelete(tableName,name);
        return "delete success";
    }
}
